﻿
//关闭当前页 返回父页面
function closePage(isReload) {
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index); //再执行关闭
    if (isReload) {
        parent.search();
    }
}

layui.use(['form', 'layer'], function () {
    var form = layui.form,
        layer = layui.layer;

    $(function () {
        loadAllButton();
        loadMenuButton();
    });
});

//加载全部按钮
function loadAllButton() {
    app.get("MenuManage.ashx", {
        ActionType: 'AllButton'
    }, function (data) {
        if (data && data.success) {
            var html = '';
            $.each(data.rows, function (index, item) {
                html += '<button type="button" id="' + item.GUID + '" ondblclick="selectedButton(this)" class="layui-btn">' + item.ButtonName + '</button>';
            });
            $('#ele-buttonlist-container').html(html);
        }
    });
};

//加载菜单按钮
function loadMenuButton() {
    $('#ele-menubutton-container').html('');
    app.get("MenuManage.ashx", {
        ActionType: 'MenuButton',
        PID: app.getRequest('pid')
    }, function (data) {
        if (data && data.success) {
            var html = '';
            $.each(data.rows, function (index, item) {
                html += '<button type="button" id="' + item.GUID + '" ondblclick="removeButton(this)" class="layui-btn">' + item.MenuName + '</button>';
            });
            $('#ele-menubutton-container').html(html);
        }
    });
};

//双击选择
function selectedButton(o) {
    app.set("MenuManage.ashx", {
        ActionType: 'AddButton',
        PID: app.getRequest('pid'),
        ButtonId: o.id
    }, function (data) {
        layer.msg(data.msg);
        if (data && data.success) {
            loadMenuButton();
        }
    });
}

//双击移除
function removeButton(o) {
    app.del("MenuManage.ashx", {
        ActionType: 'Menu',
        GUID: o.id
    }, function (data) {
        layer.msg(data.msg);
        if (data && data.success) {
            loadMenuButton();
        }
    });
}
